package com.goods.controller.business;

import com.goods.business.service.BizCategoryService;
import com.goods.business.service.BizProductService;
import com.goods.common.model.business.BizProduct;
import com.goods.common.model.business.BizProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/business/product")
@RestController
public class BizProductController {

    @Autowired
    private BizProductService bizProductService;
    @Autowired
    private BizCategoryService bizCategoryService;

    /*加载物资列表*/
    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam Map<String,Object> queryMap){
       PageVO<ProductVO> pageVO = bizProductService.findProductList(queryMap);
        return ResponseBean.success(pageVO);
    }

    //    加载商品列表(可入库)
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam Map<String,Object> queryMap){
        PageVO<ProductVO> productList = bizProductService.findProductList(queryMap);
        return ResponseBean.success(productList);
    }
    //获取库存
    @GetMapping("/findProductStocks")
    public ResponseBean findProductStocks(@RequestParam Map<String,Object> queryMap){
        PageVO<ProductStockVO> productList = bizProductService.findProductStocks(queryMap);
        return ResponseBean.success(productList);
    }
    /*获取所有库存*/
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(){
        List<ProductStockVO> productStockVOS = bizProductService.findAllStocks();
        return ResponseBean.success(productStockVOS);
    }

    /*获取分类数据*/
    @GetMapping("/getParentCategoryTree")
    public ResponseBean getParentCategoryTree() {
        List<ProductCategoryTreeNodeVO> parentCategoryTree = bizCategoryService.getParentCategoryTree();
        return ResponseBean.success(parentCategoryTree);
    }

    @PostMapping("/add")
    public ResponseBean addProduct(@RequestBody ProductVO productVO){
        bizProductService.addProduct(productVO);
        return ResponseBean.success();
    }
    @GetMapping("/edit/{id}")
    public ResponseBean editProduct(@PathVariable Integer id){
        BizProduct bizProduct = bizProductService.getProductById(id);
        return ResponseBean.success(bizProduct);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateProduct(@PathVariable Integer id, @RequestBody ProductVO productVO) {
        bizProductService.updateBizProduct(id,productVO);
        return ResponseBean.success();
    }
    /*物资添加审核*/
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Integer id) {
        bizProductService.updateProductStatus(id,0);
        return ResponseBean.success();
    }
    @PutMapping("/remove/{id}")
    public ResponseBean removeProduct(@PathVariable Integer id){
        bizProductService.updateProductStatus(id,1);//移入回收站
        return ResponseBean.success();
    }
    @PutMapping("/back/{id}")
    public ResponseBean rebackProduct(@PathVariable Integer id){
        bizProductService.updateProductStatus(id,0);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteProduct(@PathVariable Integer id) {
        bizProductService.deleteProductById(id);
        return ResponseBean.success();
    }


}
